from appium.webdriver.common.appiumby import AppiumBy

from base.wecom_app import WeComApp
from utils.log_utils import logger


class EditPersonPage(WeComApp):
    _DEL_BTN = AppiumBy.XPATH, "//*[@text='删除']"
    _NAME_BOX = AppiumBy.XPATH, "//*[@text='姓名']/following-sibling::android.widget.EditText"
    _SEX_BOX = AppiumBy.XPATH, "//*[@text='性别']/following-sibling::android.widget.RelativeLayout//*[@class='android.widget.TextView']"
    _SAVE_BTN = AppiumBy.XPATH, "//*[@text='保存']"

    def click_del_person(self):
        logger.info("滑动寻找并点击【删除成员】按钮")
        self.swipe_find("删除成员").click()

        logger.info("点击弹出页面的【删除】按钮")
        self.find_and_click(*self._DEL_BTN)

        # 进入搜索页面
        from page.address_list_search_page import AddressListSearchPage
        return AddressListSearchPage(self.driver)

    def refresh_information(self, newname):
        logger.info("修改【姓名】")
        self.find_and_change(*self._NAME_BOX, newname)

        # 须重新点一下性别 保存按钮才能点
        # 重新选一下性别
        self.find_and_reclick(*self._SEX_BOX)

        # 显示等待，按钮可点击后，点击保存按钮
        self.wait_for_click_and_click(*self._SAVE_BTN)

        # 进入个人信息页面
        from page.person_information_page import PersonInformationPage
        return PersonInformationPage(self.driver)
